#include <stdio.h>

typedef struct _Component {  
    void (*operation)(struct _Component* component);  
} Component;  
  
void ConcreteComponent_operation(Component* component) {  
    printf("ConcreteComponent operation\n");  
}  
  
typedef struct {  
    Component component;  
    // 可以添加额外的字段  
} ConcreteComponent;  
  
// 初始化 ConcreteComponent  
void ConcreteComponent_init(ConcreteComponent* cc) {  
    cc->component.operation = ConcreteComponent_operation;  
}

typedef struct _Decorator {  
    Component component;  
    Component* wrappedComponent;  
} Decorator;  
  
void Decorator_operation(Component* component) {  
    Decorator* decorator = (Decorator*)component;  
    printf("Decorator operation before\n");  
    decorator->wrappedComponent->operation(decorator->wrappedComponent);  
    printf("Decorator operation after\n");  
}  
  
typedef struct {  
    Decorator decorator;  
    // 可以添加额外的字段  
} ConcreteDecorator;  
  
// 初始化 ConcreteDecorator  
void ConcreteDecorator_init(ConcreteDecorator* cd, Component* wrapped) {  
    cd->decorator.component.operation = Decorator_operation;  
    cd->decorator.wrappedComponent = wrapped;  
}

int main() {  
    ConcreteComponent cc;  
    ConcreteComponent_init(&cc);  
  
    ConcreteDecorator cd;  
    ConcreteDecorator_init(&cd, (Component*)&cc);  
  
    // 执行操作，将会看到装饰器在原始操作前后添加的行为  
    cd.decorator.component.operation((Component*)&cd);  
  
    return 0;  
}